function createEditor(name, params) {
    
    const enableUpload = params.enableUpload,
        simpleMode = params.simpleMode,
        height = params.height,
        base64_upload_server = params.base64_upload_server,
        remote_capture_server = params.remote_capture_server,
        chunk_upload_server = params.chunk_upload_server,
        menus = params.menus;
    
    // 实例化编辑器
    const editor = new window.wangEditor(`#${name}-editor-container`);
    
    //设置编辑器 z-index`
    editor.config.zIndex = 999;
    
    // 与textarea同步
    editor.config.onchange = function (html) {
        $(`#${name}`).val(html);
    };
    
    // 输入提示
    editor.config.placeholder = '请输入内容...';
    
    // 自定义弹窗
    editor.config.customAlert = function (s, t) {
        if (s == '插入图片错误') {
            return;
        }
        var d = dialog({
            title: '提示',
            content: s,
        });
        d.show();
    };
    
    if (enableUpload) {
        
        // 自定义黏贴
        editor.config.pasteTextHandle = function (pasteStr) {
            
            setTimeout(() => {
                
                var imgs = $(`#${name}-editor-container .w-e-text-container`).contents().find("img");
                
                $(imgs).each(function (i) {
                    
                    var that = $(this);
                    
                    if (that.prop("src").match(/^data:image\/\w+;base64,/i)) {
                        
                        $.ajax({
                            url: base64_upload_server,
                            method: 'post',
                            dataType: 'json',
                            data: {
                                base64: that.prop('src'),
                            },
                            success: function (ret) {
                                if (ret.code == 1) {
                                    that.prop("src", ret.path);
                                }
                            }
                        });
                    }
                    
                    if (that.prop("src").indexOf(window.location.host) == -1 && (that.prop("src").indexOf("http://") >= 0 || that.prop("src").indexOf("https://") >= 0)) {
                        
                        $.ajax({
                            url: remote_capture_server,
                            method: 'post',
                            dataType: 'json',
                            data: {
                                url: that.prop('src'),
                            },
                            success: function (ret) {
                                if (ret.code == 1) {
                                    that.prop("src", ret.path);
                                }
                            }
                        });
                    }
                    
                });
                
            }, 100);
            
            return pasteStr;
        };
        
        // 自定义图片上传
        editor.config.uploadImgMaxSize = 5 * 1024 * 1024; // 5M
        editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif'];
        editor.config.customUploadImg = function (resultFiles, insertImgFn) {
            
            var d = dialog({
                title: '提示',
            });
            d.show();
            
            resultFiles.forEach(function (file, index, resultFiles) {
                
                // 预先插入图片占位
                var sign = encodeURIComponent(file.size + '_' + file.lastModified + '_' + file.name);
                insertImgFn(sign);
                
                var uploader = WebUploader.create({
                    // 选完文件后，是否自动上传。
                    auto: true,
                    // 文件接收服务端。
                    server: chunk_upload_server,
                    accept: {
                        title: '图片',
                        extensions: 'jpg,jpeg,png,gif',
                        mimeTypes: ['image/jpeg', 'image/png', 'image/gif'],
                    },
                    formData: {
                        // 附加表单数据
                        sign: sign,
                    },
                    compress: {
                        // 图片质量，只有type为`image/jpeg`的时候才有效。
                        quality: 90,
                        // 单位字节，如果图片大小小于此值，不会采用压缩。
                        compressSize: 1024 * 1024,
                    },
                    fileVal: 'file',
                    fileSizeLimit: 5 * 1024 * 1024,
                    fileSingleSizeLimit: 5 * 1024 * 1024,
                    chunked: true, //开启分片上传
                    chunkSize: 0.5 * 1024 * 1024,
                    method: 'POST',
                    duplicate: false,
                    sendAsBinary: false,
                });
                
                // 开始上传
                uploader.on('startUpload', function () {
                    d.content('开始上传');
                });
                
                // 上传进度显示
                uploader.on('uploadProgress', function (file, percentage) {
                    d.content('上传：' + xround(percentage * 100, 2) + '%');
                });
                
                // 上传出错
                uploader.on('uploadError', function (file, reason) {
                    d.content('上传出错：' + reason);
                });
                
                // 上传出错
                uploader.on('error', function (error) {
                    d.content('上传出错：' + error);
                });
                
                // 上传完成
                uploader.on('uploadFinished', function () {
                
                });
                
                // 上传成功
                uploader.on('uploadSuccess', function (file, ret) {
                    if (ret.code == 1 && ret.path) {
                        var imgs = $(`#${name}-editor-container .w-e-text-container`).contents().find("img");
                        $(imgs).each(function (i) {
                            if ($(this).prop("src").indexOf(ret.sign) > 0) {
                                $(this).prop("src", ret.path);
                            }
                        });
                        d.close().remove();
                    } else {
                        d.content('上传出错：' + ret.msg);
                    }
                });
                
                var uploaderFile = new WebUploader.Lib.File(WebUploader.Base.guid(), file);
                
                uploader.addFile(uploaderFile);
                uploader.upload();
                
            });
        };
        
        // 自定义视频上传
        editor.config.uploadVideoMaxSize = 512 * 1024 * 1024; // 512M
        editor.config.uploadVideoAccept = ['mp4'];
        editor.config.customUploadVideo = function (resultFiles, insertVideoFn) {
            
            var d = dialog({
                title: '提示',
            });
            d.show();
            
            resultFiles.forEach(function (file, index, resultFiles) {
                
                // 预先插入视频占位
                var sign = encodeURIComponent(file.size + '_' + file.lastModified + '_' + file.name);
                insertVideoFn(sign);
                
                var uploader = WebUploader.create({
                    // 选完文件后，是否自动上传。
                    auto: true,
                    // 文件接收服务端。
                    server: chunk_upload_server,
                    accept: {
                        title: '视频',
                        extensions: 'mp4',
                        mimeTypes: ['video/mp4'],
                    },
                    formData: {
                        // 附加表单数据
                        sign: sign,
                    },
                    fileVal: 'file',
                    fileSizeLimit: 512 * 1024 * 1024,
                    fileSingleSizeLimit: 512 * 1024 * 1024,
                    chunked: true, //开启分片上传
                    chunkSize: 0.5 * 1024 * 1024,
                    method: 'POST',
                    duplicate: false,
                    sendAsBinary: false,
                });
                
                // 开始上传
                uploader.on('startUpload', function () {
                    d.content('开始上传');
                });
                
                // 上传进度显示
                uploader.on('uploadProgress', function (file, percentage) {
                    d.content('上传：' + xround(percentage * 100, 2) + '%');
                });
                
                // 上传出错
                uploader.on('uploadError', function (file, reason) {
                    d.content('上传出错：' + reason);
                });
                
                // 上传出错
                uploader.on('error', function (error) {
                    d.content('上传出错：' + error);
                });
                
                // 上传完成
                uploader.on('uploadFinished', function () {
                
                });
                
                // 上传成功
                uploader.on('uploadSuccess', function (file, ret) {
                    if (ret.code == 1 && ret.path) {
                        var videos = $(`#${name}-editor-container .w-e-text-container`).contents().find("video");
                        $(videos).each(function (i) {
                            if ($(this).prop("src").indexOf(ret.sign) > 0) {
                                $(this).prop("src", ret.path);
                            }
                        });
                        d.close().remove();
                    } else {
                        d.content('上传出错：' + ret.msg);
                    }
                });
                
                var uploaderFile = new WebUploader.Lib.File(WebUploader.Base.guid(), file);
                
                uploader.addFile(uploaderFile);
                uploader.upload();
                
            });
        };
        
        // 自定义附件上传
        editor.config.customUploadAttachment = function (resultFiles, insertAttachmentFn) {
            
            var d = dialog({
                title: '提示',
            });
            d.show();
            
            resultFiles.forEach(function (file, index, resultFiles) {
                
                // 预先插入文件占位
                var sign = encodeURIComponent(file.size + '_' + file.lastModified + '_' + file.name);
                insertAttachmentFn(sign, file.name);
                
                var uploader = WebUploader.create({
                    // 选完文件后，是否自动上传。
                    auto: true,
                    // 文件接收服务端。
                    server: chunk_upload_server,
                    accept: {
                        title: '文件',
                        extensions: 'pdf,doc,xls,ppt,docx,xlsx,pptx,zip,rar',
                        mimeTypes: [
                            'application/pdf',
                            'application/msword',
                            'application/vnd.ms-excel',
                            'application/vnd.ms-powerpoint',
                            'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
                            'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
                            'application/vnd.openxmlformats-officedocument.presentationml.presentation',
                            'application/zip',
                            'application/x-rar-compressed',
                        ],
                    },
                    formData: {
                        // 附加表单数据
                        sign: sign,
                    },
                    fileVal: 'file',
                    fileSizeLimit: 20 * 1024 * 1024,
                    fileSingleSizeLimit: 20 * 1024 * 1024,
                    chunked: true, //开启分片上传
                    chunkSize: 0.5 * 1024 * 1024,
                    method: 'POST',
                    duplicate: false,
                    sendAsBinary: false,
                });
                
                // 开始上传
                uploader.on('startUpload', function () {
                    d.content('开始上传');
                });
                
                // 上传进度显示
                uploader.on('uploadProgress', function (file, percentage) {
                    d.content('上传：' + xround(percentage * 100, 2) + '%');
                });
                
                // 上传出错
                uploader.on('uploadError', function (file, reason) {
                    d.content('上传出错：' + reason);
                });
                
                // 上传出错
                uploader.on('error', function (error) {
                    d.content('上传出错：' + error);
                });
                
                // 上传完成
                uploader.on('uploadFinished', function () {
                
                });
                
                // 上传成功
                uploader.on('uploadSuccess', function (file, ret) {
                    if (ret.code == 1 && ret.path) {
                        var attachments = $(`#${name}-editor-container .w-e-text-container`).contents().find("a");
                        $(attachments).each(function (i) {
                            if ($(this).prop("href").indexOf(ret.sign) > 0) {
                                $(this).prop("href", ret.path);
                            }
                        });
                        d.close().remove();
                    } else {
                        d.content('上传出错：' + ret.msg);
                    }
                });
                
                var uploaderFile = new WebUploader.Lib.File(WebUploader.Base.guid(), file);
                
                uploader.addFile(uploaderFile);
                uploader.upload();
                
            });
        };
    }
    
    // 扩展按钮
    // menus: [
    //     {
    //         key: 'save', // 菜单的标识名称
    //         index: 0, // 菜单的位置
    //         obj: 菜单对象, // 必须继承自wangEditor的菜单对象基类
    //     }
    // ],
    if (menus) {
        menus.forEach((menu) => {
            editor.menus.extend(menu.key, menu.obj);
            editor.config.menus.splice(menu.index, 0, menu.key);
        });
    }
    
    if (simpleMode) {
        editor.config.excludeMenus = [
            'todo',
            'table',
            'code',
            'fontName',
            'foreColor',
            'backColor',
            'fontSize',
            'strikeThrough',
            'quote',
            'video',
            'indent',
            'list',
            'splitLine',
            'undo',
            'redo',
            'attachment',
        ];
        
        editor.config.showFullScreen = false;
    }
    
    // 取消自动聚焦
    editor.config.focus = false;
    
    // 创建编辑器
    editor.create();
    
    // 自动高度
    $(`#${name}-editor-container .w-e-text-container`).css({height: height ? height : 'auto', minHeight: '300px'});
    
    return editor;
}